<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
    <script>
        function getQueryVariable(variable)
        {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
            }
            return null;
        }
        var code = getQueryVariable('code')

        $(function(){

           $.ajax({
            // 请求方式
            type:"get",
            // dataType
            dataType:"json",
            // url
            url:"http://127.0.0.1:8000/v1/users/weibo/token?code="+code,
            // result 为请求的返回结果对象
            success:function (result) {
                console.log(result)
                if (200 == result.code){
                    //存储token
                window.localStorage.setItem('dnblog_token', result.data.token)
                window.localStorage.setItem('dnblog_user', result.username)
                alert("登录成功 您已绑定过用户，现在将跳转到您的个人主页")
                    window.location =  'http://127.0.0.1:5000/' + result.username + '/topics';
                }else if (222 == result.code) {
                    var wuid = result.uid
                    window.location = 'http://127.0.0.1:5000/register?wuid=' + wuid
                }else{
                    alert(result.error)
                }
            }
            });

        })



    </script>




</body>
</html>